from selenium import webdriver
import unittest
import time
import os,sys,csv
from ddt import ddt,unpack,data,file_data

# #如何读取TXT 文件中的数据形成数组
# def getTxt(file_name):
#     #[[周迅，周迅_百度搜索],[张国荣，张国荣_百度搜索],[周杰伦，周杰伦_百度搜索]]
#     rows = []
#     path = sys.path[0]
#     with open(path+'/data/'+file_name, 'rt') as f:
#         readers = csv.reader(f, delimiter=',', quotechar='|')
#         next(readers,None)
#         for row in readers:
#             temprows=[]
#             for i in row:
#                 #周迅，周迅_百度搜索
#                 temprows.append(i)
#             rows.append(temprows)
#         print(rows)
#         return rows

@ddt
class Baidu4(unittest.TestCase):
    def setUp(self):
        print("-----setUp-----")
        self.driver = webdriver.Chrome()
        self.url = "https://www.baidu.com/"
        self.driver.maximize_window()
        time.sleep(3)
    def tearDown(self):
        print("-----tearDown-----")
        self.driver.quit()

    @data("jennie", "周杰伦", "林俊杰")
    def test_search1(self,value):
        driver = self.driver
        url = self.url
        driver.get(url)
        time.sleep(3)
        driver.find_element_by_id("kw").clear()
        driver.find_element_by_id("kw").send_keys(value)
        driver.find_element_by_id("su").click()
        time.sleep(3)

if __name__ == "__main__":

        unittest.main(verbosity=2)